define(['./../initial', './../model/User', './../model/Project', './../controller/admin/admin.userCtrl', './../controller/admin/admin.user.configCtrl', './../controller/admin/admin.projectCtrl', './../controller/admin/admin.project.configCtrl', './../service/showMsg'], function() {

    var app = angular.module('App.home');
    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function($stateProvider, $urlRouterProvider, $locationProvider) {


            $urlRouterProvider.when('/admin', ['$stateParams', '$state', function($stateParams, $state) {
                $state.go('admin.user');
            }]);

            $stateProvider
                .state('admin', {
                    url: "/admin",
                    templateUrl: "/partials/admin/admin",
                    resolve: {
                        User: 'User',
                        Project: "Project",
                        showMsg: 'showMsg',
                        authorizedUsers: ["User", function(User) {
                            var u = new User();
                            return u.getAuthorizedUsers();
                        }],
                        cityList: ["Project", function(Project) {
                            return Project.getAllCityList();
                        }]
                    },
                })
                .state('admin.user', {
                    url: "/user",
                    resolve: {
                        userCorps: ["User", 'authorizedUsers', function(User, authorizedUsers) {
                            return User.convertAuthorizedUsersInCorp(authorizedUsers);
                        }]
                    },
                    templateUrl: "/partials/admin/admin/user",
                    controller: 'admin.userCtrl'
                })
                .state('admin.user.config', {
                    url: "/{userName}",
                    resolve: {
                        curPerson: ["authorizedUsers", "$stateParams", function(authorizedUsers, $stateParams) {
                            var userName = $stateParams.userName;
                            var user = authorizedUsers.filter(function(item) {
                                return item.userName === userName;
                            })[0];
                            return user;
                        }]
                    },
                    templateUrl: "/partials/admin/admin/user/config",
                    controller: 'admin.user.configCtrl'
                })
                .state('admin.project', {
                    url: "/project",
                    resolve: {
                        userCorps: ["User", 'authorizedUsers', function(User, authorizedUsers) {
                            return User.convertAuthorizedUsersInCorp(authorizedUsers);
                        }]
                    },
                    templateUrl: "/partials/admin/admin/project",
                    controller: 'admin.projectCtrl'
                })
                .state('admin.project.config', {
                    url: "/{prjId:[0-9]+}",
                    resolve: {
                        curPrj: ['$stateParams', 'Project', 'cityList',
                            function($stateParams, Project, cityList) {
                                return Project.getCurProject($stateParams.prjId);
                            }
                        ]
                    },
                    onEnter: function() {
                        $('.prj-header').popup('remove');
                    },
                    templateUrl: "/partials/admin/admin/project/config",
                    controller: 'admin.project.configCtrl'
                });
        }
    ]);
});
